package com.example.io;

import java.io.*;
import java.util.Arrays;
import java.util.function.IntFunction;


/*
 *
 * du
 * 读取a.txt文件内容并将其内容排序输出在dest.txt文件中
 *
 * */


public class Test03 {
    public static void main(String[] args) throws IOException {
        //关联文件
        File file = new File("D:\\27162\\Desktop\\itheima\\untitled2", "a.txt");
        //读取数据
        FileReader fileReader = new FileReader(file);
        StringBuilder builder = new StringBuilder();
        int ch;
        while ((ch = fileReader.read()) != -1) {
            builder.append((char) ch);
        }

        fileReader.close();

        System.out.println(builder);
        //排序

        Integer[] arrays = Arrays.stream(builder.toString().split("-")).map(Integer::parseInt).sorted().toArray(Integer[]::new);
        //写入数据
        FileWriter fileWriter = new FileWriter("D:\\27162\\Desktop\\itheima\\untitled2\\dest.txt");
        String replaced = Arrays.toString(arrays).replace(", ", "-");
        System.out.println(replaced);
        String substringed = replaced.substring(1, replaced.length() - 1);
        System.out.println(substringed);
        fileWriter.write(substringed);
        //关闭通道
        fileWriter.close();
    }
}
